package com.tyqx.hashchainbiz.service.impl;

import com.tyqx.hashchainbean.module.TrackUser;
import com.tyqx.hashchainbiz.service.TrackUserRegisterService;
import com.tyqx.hashchaindao.mapper.TrackUserMapper;
import hashchainutil.exception.HashchainException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @program: dcep-spring
 * @description:
 * @author: Mr.Li
 * @create: 2020-04-19 04:08
 **/
@Service("trackUserRegisterService")
public class TrackUserRegisterServiceImpl implements TrackUserRegisterService {

    @Resource
    private TrackUserMapper trackUserMapper;

    @Override
    public boolean saveNewUser(TrackUser trackUser) throws Exception {
            try {
                //密码MD5加密
               //String encryptPwd = DigestUtil.hmacSign(trackUser.getPassword());
                PasswordEncoder passwordEncoder=new BCryptPasswordEncoder();

                String encodedPassword=passwordEncoder.encode(trackUser.getPassword());
                trackUser.setPassword(encodedPassword);
                if (trackUserMapper.save(trackUser) > 0) {
                    return true;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        throw new HashchainException("新增注册信息失败", "100001");
    }


}
